<style lang="scss">
</style>
<template>
  <div class="orderMerchantDetails">
    <uv-collapse>
      <uv-collapse-item title="" name="Docs guide">
        <uv-radio-group size="mini" v-model="row.MMMMM">
          <uv-radio label="待商家处理" name="待商家处理"></uv-radio>
          <uv-radio label="消费者处理" name="消费者处理"></uv-radio>
          <uv-radio label="退货待处理" name="退货待处理"></uv-radio>
          <uv-radio label="商家举证" name="商家举证"></uv-radio>
          <uv-radio label="买家举证" name="买家举证"></uv-radio>
          <uv-radio label="平台处理" name="平台处理"></uv-radio>
          <uv-radio label="商家举证即将逾期" name="商家举证即将逾期"></uv-radio>
          <uv-radio label="退款成功" name="退款成功"></uv-radio>
          <uv-radio label="撤销申请" name="撤销申请"></uv-radio>
        </uv-radio-group>

        <uv-radio-group size="mini" v-model="row.PPPPP" @change="row.KKKKK = (row.PPPPP == '未收到货' ? '退款' : '退货退款')">
          <uv-radio label="未收到货" name="未收到货"></uv-radio>
          <uv-radio label="已收到货" name="已收到货"></uv-radio>
        </uv-radio-group>
        <uv-radio-group size="mini" v-model="row.KKKKK">
          <uv-radio :disabled="row.PPPPP === '已收到货'" label="退款" name="退款"></uv-radio>
          <uv-radio :disabled="row.PPPPP === '未收到货'" label="退货退款" name="退货退款"></uv-radio>
        </uv-radio-group>
        <uv-radio-group size="mini" v-model="row.EEEEE">
          <uv-radio label="发货物流" name="发货物流"></uv-radio>
          <uv-radio label="退货物流" name="退货物流"></uv-radio>
        </uv-radio-group>
      </uv-collapse-item>

    </uv-collapse>

    <div class="" style="top: 0;position: absolute;height: 1px;background: #EFEFEF;width:100%"></div>
    <div class="" style="height: 100%; overflow-y: auto">
      <div class="bfff  pb20 pt30 ">
        <u-lst-order-top :row="row">
          <button @click="commonButtonTap(1)" class="common-button fz28 bD60012 " style="width: 180rpx;height: 70rpx;color: #fff; border: 1rpx solid #D60012!important; ">发货</button>
        </u-lst-order-top>
        <u-lst-order-reason :row="row">
          <div class=" pr30 pt20 mt30" style="text-align: right;border-top: 1px solid #EFEFEF">
            <button v-if="row.MMMMM === '退款成功'" @click="commonButtonTap(1)" class="common-button cD60012 fz28 bfff pl10 pr10" style="height: 60rpx;border: 1rpx solid #C9CACA!important; ">售后申诉</button>
            <button v-if="row.MMMMM === '待商家处理' || row.MMMMM === '退货待处理' || row.MMMMM === '消费者处理'" @click="commonButtonTap(1)" class="common-button cD60012 fz28 bfff pl10 pr10" style="height: 60rpx;border: 1rpx solid #C9CACA!important; ">平台介入</button>
            <button v-if="row.MMMMM === '待商家处理'" @click="commonButtonTap(1)" class="common-button cD60012 fz28 bfff pl10 pr10 ml20" style="height: 60rpx;border: 1rpx solid #C9CACA!important; ">驳回申请</button>
            <button v-if="(['待商家处理' , '商家举证', '消费者处理', '买家举证', '平台处理'].includes(row.MMMMM)) && row.PPPPP === '未收到货' && row.KKKKK === '退款' && row.EEEEE === '发货物流' " @click="commonButtonTap(1)" class="common-button ml20 cD60012 fz28 bfff pl10 pr10" style="height: 60rpx;border: 1rpx solid #C9CACA!important; ">同意拒收后退款</button>
            <button v-if="row.MMMMM === '退货待处理' && row.PPPPP === '已收到货' && row.KKKKK === '退货退款' && row.EEEEE === '退货物流' " @click="commonButtonTap(1)" class="common-button ml20 cD60012 fz28 bfff pl10 pr10" style="height: 60rpx;border: 1rpx solid #C9CACA!important; ">拒收退货</button>
            <button v-if="['待商家处理' , '商家举证', '消费者处理', '买家举证', '平台处理', '商家举证即将逾期'].includes(row.MMMMM)" @click="commonButtonTap(1)" class="common-button fz28 bD60012 cfff ml20 pl10 pr10" style="height: 60rpx;border: 1rpx solid #D60012!important;">同意{{ row.KKKKK }}</button>
            <button v-if="row.MMMMM === '退货待处理'" @click="commonButtonTap(1)" class="common-button fz28 bD60012 cfff ml20 pl30 pr30" style="height: 60rpx;border: 1rpx solid #D60012!important;">退款</button>
          </div>
        </u-lst-order-reason>
      </div>

      <div v-if="row.status != 1 && row.status != 2" class="bfff mt20">
        <div class="fz32 pl30 pr30 pt20 pb20  fw500">物流信息</div>
        <div class="fz28 f aic jcsb p1758091777 pt20 pb20 pl20 pr20" style="color: #595757">
          <div class="f aic ">
            <uv-icon name="car" size="42rpx" color="#595757" />
            <div class="dib pl20">中通快递 {{row.freight_no}}</div>
          </div>
          <button @click="handleCopy(row.freight_no)" class="common-button fz24 pt5 ml0 mr0 pb5 bfff pl20 pr20  " style="border: 1rpx solid #C9CACA!important;">复制</button>
        </div>
        <div></div>

      </div>
      <div class="bfff mt20">
        <div class="p1758091777 lh1 bfff pb30 pl30 pt30   fz30">
          <div class=""> {{row.merchant_order.address_name}} </div>
          <div class=" pt20 pb20"> {{row.merchant_order.address_tel}} </div>
          <div class="" style="">
            <div class="dib">{{row.merchant_order.address_province}}</div>
            <div class="dib">{{row.merchant_order.address_city}}</div>
            <div class="dib">{{row.merchant_order.address_area}}</div>
            <div class="dib">{{row.merchant_order.address_town}}</div>
            <div class="dib">{{row.merchant_order.address_house_number}}</div>
          </div>
        </div>
        <div class="pt20 pr30 pb20" style="text-align: right">
          <button v-if="row.status == 2" @click="uni.navigateTo({ url: '/pages-merchant/trackShipment?id='});" class="common-button c333 fz26 bfff ml20" style="width: 140rpx;height: 55rpx;border: 1rpx solid #C9CACA!important; ">修改地址</button>
          <button v-if="row.status == 2" @click="uni.navigateTo({ url: '/pages-merchant/trackShipment?id='});" class="common-button c333 fz26 bfff ml20" style="width: 140rpx;height: 55rpx;border: 1rpx solid #C9CACA!important; ">核对地址</button>
          <button @click="handleCopy()" class="common-button c333 fz26 bfff ml20" style="width: 140rpx;height: 55rpx;border: 1rpx solid #C9CACA!important; ">复制</button>
        </div>
      </div>
      <div class="fz32 pl30 pr30 mt20 f aic jcsb pt20 pb20 bfff fw500">
        <div>商品信息</div>
        <div v-if="row.status != 1" class="f aic">
          <div class="f aic jcc" style="height: 40rpx;overflow: hidden">
            <uv-avatar shape="square" :src="row.avatar" size="30rpx"></uv-avatar>
          </div>
          <div class="pl10 fz26 pr10 " style="color: #516AFE">联系 {{row.nickname}}</div>
        </div>
      </div>
      <div>
        <div class="f bfff pt30 pl30 pr30 pb30 p1758091777">
          <img class="product_image" :src="row.product_image" alt="avatar">
          <div class="pl20">
            <div class="f  lh1 jcsb ">
              <div style="" class="fz28 dib    product_name">{{row.product_name}}&nbsp;</div>
              <div style="min-width: 100rpx;text-align: right;line-height:1.3" class="fz28  ">
                <div>¥{{row.price}}</div>
                <div style="min-width: 100rpx;text-align: right" class="fz28">x{{ row.cart_num }}</div>
              </div>
            </div>
            <div class="pt20 lh1" style="color: #898989">商品编码：</div>
            <div class="pt10 lh1" style="color: #898989">
              <div class="dib pr10">{{row.order_no}}</div>
              <button @click="handleCopy()" class="common-button fz24 pt5 pb5 bfff pl20 pr20 s09 " style="border: 1rpx solid #C9CACA!important;">复制</button>
            </div>
            <div class="pt10 lh1" style="color: #898989">{{row.spec_values}}</div>
          </div>
        </div>
        <div style="color:#595757" class="pay_price pl30 pr30 bfff pt30 pb30 f aic jcsb  lh1 ">
          <div class=" dib">商品总价</div>
          <div class="fw500  dib">¥{{row.pay_price}}</div>
        </div>
        <div style="text-align:right" class=" bfff pb20  pr30 fw500 fz30 ">商家实收：¥{{row.pay_price}}</div>
        <div class="pt20 pr30 pb20 bfff" style="text-align: right; border-top: 1px solid #efefef;">
          <button @click="uni.navigateTo({ url: '/pages-merchant/trackShipment?id='});" class="common-button c333 fz26 bfff ml20" style="width: 140rpx;height: 55rpx;border: 1rpx solid #C9CACA!important; ">小额打款</button>
        </div>
        <div v-if="row.status != 1" class=" pl30 pr30 mt20 pr30 f aic jcsb pt20 pb20 bfff ">
          <div class="fw500 fz32">协商详情</div>
          <div class="f aic ">
            <div class="lh1" style="color: #C9CACA">您可添加留言/上传凭证</div>
            <div style="padding-top:2rpx ">
              <uv-icon color="#C9CACA" size="28rpx" name="arrow-right"></uv-icon>
            </div>
          </div>
        </div>
        <div class="pl30 pt20 pb20 mt20 bfff" style="color: #898989">
          <div class="pt20" v-for="(item, index) in orderForm[row.status]" :key="index">
            <div class="dib pr10">{{item.text}}：{{item.value || row[item.prop]}}</div>
            <button @click="handleCopy(row[item.prop])" v-if="item.text == '订单编号'" class="common-button fz24 pt5 pb5 bfff pl20 pr20 s09 " style="border: 1rpx solid #C9CACA!important;">复制</button>
            <button v-if="item.text == '商品快照'" class="common-button fz24 pt5 pb5 bfff pl20 pr20 s09 " style="border: 1rpx solid #C9CACA!important;">查看</button>
          </div>
        </div>

        <div v-if="row.status == 2" class="pt20 pr30 pb20 bfff" style="text-align: right; border-top: 1px solid #efefef;">
          <button @click="$refs.actionSheet.open();" class="common-button c333 fz30 bfff " style="width: 180rpx;height: 70rpx;border: 1rpx solid #C9CACA!important; ">更多</button>
          <button @click="commonButtonTap(1)" class="common-button fz30 ml20 bD60012 " style="width: 180rpx;height: 70rpx;color: #fff; border: 1rpx solid #D60012!important; ">发货</button>
        </div>
      </div>

    </div>
    <uv-safe-bottom />
    <uv-action-sheet safeAreaInsetBottom ref="actionSheet" :actions=" [{ name: '申诉异常单' }]" cancelText="取消" :closeOnClickOverlay="false" @select="select" @close="close"></uv-action-sheet>
  </div>
</template>

<script>
import orderTopVue from "../components/orderTop.vue";
import orderReasonVue from "../components/orderReason.vue";
import goodVue from "../components/good.vue";
import pageMixin from "../mixin/page.js";
import commonMixin from "../mixin/common.js";
import { orderList } from "@/api/merchant.js";
export default {
  components: {
    "u-lst-order-top": orderTopVue,
    "u-lst-order-reason": orderReasonVue,
    "u-lst-good": goodVue,
  },
  mixins: [commonMixin, pageMixin],
  data() {
    return {
      show: false,
      remarkCurrent: 0,
      checkboxValue: [],
      form: {
        MMMMM: 1,
        KKKKK: 1,
        limit: 10,
        status: 1
      },
      current: 0,
      row: {
        status: 3,
        "id": 8,
        "user_id": 54,
        "merchant_order_id": 7,
        "order_id": 7,
        "order_no": "PT542509171512573750101931",
        "product_id": 141,
        "sku_id": 0,
        "price": "35.70",
        "cart_num": 1,
        "total_price": "35.70",
        "merchant_coupon_price": "0.00",
        "platform_coupon_price": "0.00",
        "pay_price": "35.70",
        "delivery_id": 0,
        "freight_no": "",
        "return_address_id": 0,
        "delivery_time": null,
        "after_sales_id": 0,
        "apply_after_sales_time": null,
        "profit_sharing_amount": "0.00",
        "create_time": "2025-09-17 15:12:57",
        "update_time": "2025-09-17 15:12:57",
        "delete_time": null,
        "merchant_order": {
          "id": 7,
          "address_name": "朱志鹏",
          "address_tel": "13791944514",
          "address_province": "江苏省",
          "address_city": "泰州市",
          "address_area": "靖江市",
          "address_town": "靖城街道办",
          "address_storey": "蛋糕店",
          "address_house_number": "3单元",
          "address_latitude": "32.02020100",
          "address_longitude": "120.27"
        },
        "product_name": null,
        "product_image": "https://linshitong.oss-cn-shenzhen.aliyuncs.com/dev/image/2025/0913/d39fb202509131410349290.png",
        "spec_values": "",
        "nickname": "用***"
      },
      statusTextForm: {
        1: '待付款',
        3: '已发货，待收货',
        4: '待评价',
        5: '退款售后',
        2: '待发货',
        7: '已完成',
      },
      orderForm: {
        1: [{ text: '订单编号', prop: 'order_no' }, { text: '下单时间', prop: '' }],
        2: [
          { text: '订单编号', prop: '' }, { text: '商品快照', value: '核对交易细节时，可作为判断依据', }, { text: '承诺发货时间', prop: '' },
          { text: '下单时间', prop: '' }, { text: '付款时间', prop: '' }, { text: '成交时间', prop: '' }],
        3: [
          { text: '订单编号', prop: 'order_no' }, { text: '商品快照', value: '核对交易细节时，可作为判断依据', }, { text: '承诺发货时间', prop: 'delivery_time' },
          { text: '下单时间', prop: 'create_time' }, { text: '付款时间', prop: '' }, { text: '成交时间', prop: '' }],
        4: [{ text: '订单编号：', prop: '' }, { text: '下单时间：', prop: '' }],

      },
      list: [
        { name: "待付款", status: 1, badge: { value: 0, } },
        { name: "待发货", status: 2, badge: { value: 0, } },
        { name: "待收货", status: 3, badge: { value: 0, } },
        { name: "待评价", status: 4, badge: { value: 0, } },
        { name: "已完成", status: 7, badge: { value: 0, } },
        { name: "退款售后", status: 5, badge: { value: 0, } },
      ],
      remarkList: [{ name: '待商家处', badge: { value: 1, } }, { name: '待举证即将逾', }, { name: '待商家处1' }]
    };

  },
  onShow() {
  },
  onLoad() {
  },
  methods: {
    // 1-发货
    commonButtonTap(type) {
      uni.removeStorage({ key: 'storageForm' });
      if (type == 2) {
        uni.navigateTo({ url: '/pages-merchant/combinedShipping' })
        return
      }
      let { id, order_no, merchant_order_id, product_name, spec_values, price, product_image, cart_num, merchant_order, status } = this.row
      let obj = { id, order_no, merchant_order_id, product_name, spec_values, price, product_image, cart_num, merchant_order, status }
      if (type == 1) {
        uni.setStorage({ key: 'storageForm', data: JSON.stringify(obj) });
        uni.navigateTo({ url: '/pages-merchant/shipment?id=' + this.row.id });
      }
    },
    handleCopy(content) {
      let { address_name, address_tel, address_province, address_city, address_area, address_town, address_storey, address_house_number } = this.row.merchant_order
      content = !content ? `${address_name} \n${address_tel} \n${address_province + address_city + address_area + address_town + address_storey + address_house_number}` : content
      uni.setClipboardData({
        data: content,
        success: () => {
          uni.showToast({ title: '复制成功', icon: 'none', duration: 2000, });
        },
        fail: (err) => {
          uni.showToast({ title: err, icon: 'none', duration: 2000, });
        },
      });
    },
    open() {
      this.$refs.actionSheet.open();
    },
    select(e) {
      console.log('选中该项：', e);
    },
    close() {
      console.log('关闭');
    },
    initPage(cb = () => { }) {
      this.isOnce = false;
      if (this.form.page == this.current_page) return;
      uni.showLoading({
        title: "加载中",
        mask: true,
      });
      let form = JSON.parse(JSON.stringify(this.form));
      form.status = 2
      orderList(form).then((res) => {
        this.isRefreshing = false;
        this.isOnce = true;

        if (res.code === 200) {
          cb();
          uni.hideLoading();
          let data = []
          if (res?.result?.data) {
            data = res.result.data.map(i => {

              //                          <!-- status
              // integer 
              // 必需
              // 订单状态：1=待支付，2=待发货，3=待收货，4=待评价，5=已取消，6=已售后，7=已完成 -->
              i.status = this.form.status
              return i
            })
          }
          this.total = res.result.total;
          this.current_page = res.result.current_page;
          this.tableData = this.tableData.concat(data);
          if (this.total <= this.tableData.length) this.status = "nomore";
        }
      })
        .catch(() => {
          uni.hideLoading();
          this.isRefreshing = false;
          this.isOnce = true;
        });
    },
  },
};
</script>
<style>
page {
  background-color: #f7f8f8;
  color: #333333;
  font-size: 28rpx;
}
</style><style lang="scss" scoped>
@import "../common.scss";
.orderMerchantDetails {
  .product_image {
    width: 120rpx;
    min-width: 120rpx;
    height: 120rpx;
    border-radius: 4rpx;
    border: 1px solid #efefef;
  }
  .product_name {
    max-width: calc(100vw - 310rpx);
    min-width: calc(100vw - 310rpx);
    line-height: 1.3;

    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    text-align: left;
  }
  .p1758091777 {
    border-top: 1px solid #efefef;
    border-bottom: 1px solid #efefef;
  }
}
</style>
